package banwood.com.xiongfasy.http;

import android.content.Context;
import android.os.AsyncTask;
import android.widget.Toast;

import banwood.com.xiongfasy.R;
import banwood.com.xiongfasy.listener.ResultListener;
import banwood.com.xiongfasy.utils.NetUtils;
import cn.shellinfo.serv.comm.ParamMap;

/**
 * Created by Administrator on 2017/5/10 0010.
 */

public class GetAsynctask extends AsyncTask<ParamMap,Void,ParamMap> {
    private static String TAG="GetAsynctask";

    ResultListener mListener;
    private Context mContext;
    private ParamMap mParamMap;
    private String processorName;

    public GetAsynctask(ResultListener listener, Context context, ParamMap paramMap, String name) {
        this.mListener = listener;
        this.mContext = context;
        this.mParamMap=paramMap;
        this.processorName=name;
    }

    @Override
    protected ParamMap doInBackground(ParamMap... params) {
        ParamMap result = CommonImpl.getInstance(mContext).getLogin(mParamMap, processorName);
        return  result;
    }

    @Override
    protected void onPostExecute(ParamMap result) {
        if(result!=null){
            if( "0000".equals(result.get("ReturnCode"))){
                mListener.getResult(result);
            }else{
                if(!processorName.equals("getMerchantPaymentReturn")){
                    Toast.makeText(mContext,result.getString("ErrorMessage",""),Toast.LENGTH_SHORT).show();
                }
                mListener.getResult(null);
            }
        }else{
            if(!NetUtils.isNet(mContext)){
                Toast.makeText(mContext,mContext.getResources().getString(R.string.net_error),
                        Toast.LENGTH_LONG).show();
                mListener.getResult(null);
            }
        }

    }
}
